export const hasItems = (list: any[], filed: string, target: string): boolean => {
  for (let i = 0; i < list.length; i++) {
    const element = list[i];
    if (element[filed] === target) {
      return true;
    } else {
      if (element.child && element.child.length > 0 && hasItems(element.child, filed, target))
        return true;
    }
  }
  return false;
};

export const findItem = (list: any[], filed: string, target: any, childField = 'child'): any => {
  for (let i = 0; i < list.length; i++) {
    const element = list[i];
    if (element[filed] === target) {
      return element;
    } else {
      if (element[childField] && element[childField].length > 0) {
        const item = findItem(element[childField], filed, target);
        if (item) {
          return item;
        }
      }
    }
  }
  return false;
};
